package process_demo.review.about_lock.locks;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author haomin
 * @date 2022/09/10 16:05
 **/
public class Main2 {
    static Lock lock = new ReentrantLock();
    static class MyThread1 extends Thread{
        @Override
        public void run() {
            boolean b = false;
            try {
                lock.lockInterruptibly();
                while(true){
                    System.out.println("执行程序");
                }
            } catch (InterruptedException e) {
                System.out.println("中断打断");
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread1 t1 = new MyThread1();
        t1.start();
        TimeUnit.SECONDS.sleep(2);
        t1.interrupt();
        t1.join();
    }
}